package com.yixiang.np.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yixiang.np.annotation.SystemControllerLog;
import com.yixiang.np.model.Grid;
import com.yixiang.np.model.Json;
import com.yixiang.np.model.PageFilter;
import com.yixiang.np.model.po.Log;
import com.yixiang.np.service.LogServiceI;

@Controller
@RequestMapping("/log")
public class LogController extends BaseController { 
    @Autowired
    private LogServiceI logService;

    @RequestMapping("/manager")
    public String manager() {
        return "/admin/log";
    }

    @RequestMapping("/dataGrid")
    @ResponseBody
    @SystemControllerLog(module = "订单日志管理", methods = "日志管理-添加订单日志")
    public Grid dataGrid(Log log, PageFilter ph) {
        Grid grid = new Grid();
        grid.setRows(logService.dataGrid(log, ph));
        grid.setTotal(logService.count(log, ph));
        return grid;
    }
    @RequestMapping("/bootGrid")
    @ResponseBody
    @SystemControllerLog(module = "订单日志管理", methods = "日志管理-添加订单日志")
    public Grid bootGrid(Log log, PageFilter ph) {
        Grid grid = new Grid();
        grid.setRows(logService.dataGrid(log, ph));
        grid.setTotal(logService.count(log, ph));
        return grid;
    }
    @RequestMapping("/view")
    public String view(HttpServletRequest request, Long id) {
        Log log = logService.get(id);
        request.setAttribute("log", log);
        return "/admin/logView";
    }

    @RequestMapping("/delete")
    @ResponseBody
    @SystemControllerLog(module = "系统管理", methods = "日志管理-清空日志")
    public Json delete(Long id) {
        Json j = new Json();
        try {
            logService.delete(id);
            j.setMsg("删除成功！");
            j.setSuccess(true);
        } catch (Exception e) {
            j.setMsg(e.getMessage());
        }
        return j;
    }
 
}
